<?php

// Copyright (c) 2012 Mirza Adipradhana
/*
 * Sentralisasi keseluruhan Error Message
 * Multi-language support
 */



class ErrorHandler {

    private $mLang;
    private $mErrorMessage = array();
    private $mErrorSection;
    private $mErrorCode;
    private $mCallerClass;

    public function __construct($_ERRORS, $pLang= "ID") {
        $this->mLang = $pLang;

        $this->mErrorMessage = $_ERRORS;
        ///$this->mCallerClass = (!empty($pParams['caller'])) ? $pParams['caller'] : null;
        // $this->LoadErrorCode();
    }

    public function GetErrorMessage() {
        $tOutput = "<div class=\"Title\">" . $this->mErrorMessage[$this->mLang][$this->mErrorSection][$this->mErrorCode]["TITLE"] . "</div>";
        $tOutput.= "<div class=\"Content\">" . $this->mErrorMessage[$this->mLang][$this->mErrorSection][$this->mErrorCode]["CONTENT"] . "</div>";
        return $tOutput;
    }

    ////
    // M U T U A T O R
    public function SetErrorSection($pValue) {
        $this->mErrorSection = $pValue;
    }

    public function SetErrorCode($pValue) {
        $this->mErrorCode = $pValue;
    }

    public function GetErrorSection() {
        return $this->mErrorSection;
    }

    public function GetErrorCode() {
        return $this->mErrorCode;
    }

    ////



    public function Alert($pCode = null, $pFlag = null) {
        $tMsg = $this->GetErrorMessage($pCode);
        if (!strlen($tMsg)) {
            $tMsg = $pCode;
        }
        if ($pFlag == null) {
            echo '<scirpt>alert("' . $tMsg . '"); history.go(-1)</script>';
        } else if (!strcmp($pFlag, 'close')) {
            echo '<scirpt>alert("' . $tMsg . '"); window.close();</script>';
        } else {
            echo '<scirpt>alert("' . $tMsg . '"); </script>';
        }
    }

    

}

?>